home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
bin2arr.zip
/
SOURCE.ZIP
/
BIN2INC.CPP
< prev
Wrap
C/C++ Source or Header
|
1994-12-27
|
4KB
|
164 lines
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<io.h>
#include<fcntl.h>
coolprintf(char *string,char FIRST_COLOR = 8,char SECOND_COLOR=7,char REST_COLOR=15)
{
register int stringloop;
char first_letter;
textcolor(FIRST_COLOR);
cprintf("%c",string[0]);
textcolor(SECOND_COLOR);
cprintf("%c",string[1]);
textcolor(REST_COLOR);
stringloop=1;//2
while(string[stringloop++] != NULL)
{
if (first_letter==1)
{
textcolor(FIRST_COLOR);
cprintf("%c",string[stringloop]);
textcolor(SECOND_COLOR);
cprintf("%c",string[stringloop+1]);
stringloop++;
first_letter=0;
textcolor(REST_COLOR);
}
else
cprintf("%c",string[stringloop]);
if (string[stringloop]==32) first_letter=1;
}
return 0;
}
char coolgets(char *string,char FIRST_COLOR = 2,char REST_COLOR=10)
{
unsigned char c;
int count=1;
string[0]=32;
char space_bar=0;
while ((c = getch()) != 13 )
{
if(c==8)
{
string[count-2]=32;
if (count>1) cprintf("%c%c%c",8,32,8);
else space_bar=0;
count--;
if (count<1) count =1;
//if (string[count-2]==32) space_bar=0;
if (string[count-2]==32) space_bar=0;
if (count <1) if (string[count-2]==32) space_bar=0;
else space_bar=1;
}
if (c>32 && c<128 || c == 32)
{
if (count <50)
{
count++;
if (space_bar==0) {textcolor(FIRST_COLOR); space_bar=1;}
else textcolor(REST_COLOR);
if (c>32 && c<65) textcolor(REST_COLOR);
if (c>47 && c<60) textcolor(FIRST_COLOR);
string[count-2]=c;
cprintf("%c", c);
space_bar=0;
if (c==32) space_bar=0;
else space_bar=1;
}
}
}
printf("\n");
string[count-1]=NULL;
return 0;
}
main(int argc,unsigned char* argv[])
{
if (argc<3)
{
printf("\n");
coolprintf("Usage:");
printf("\n");
coolprintf("BIN2ASM [SOURCE BINARY] [OUTPUT ASM INCLUDE FILE]");
printf("\n");
exit(1);
}
unsigned char string[80];
unsigned char buf[10];
unsigned char array_name[80];
unsigned long count,fl,count2=0,line=0;
int handle;
FILE *fp;
if ((handle = open(argv[1], O_RDONLY | O_BINARY)) == -1)
{
printf("\n");
sprintf(string,"Error: Cannot Open '%s'",argv[1]);
coolprintf(string);
printf("\n");
exit(1);
}
if((fp = fopen(argv[2], "w+")) ==NULL)
{
printf("\n");
sprintf(string,"Error: Cannot Create '%s'",argv[2]);
coolprintf(string);
printf("\n");
exit(1);
}
fl=filelength(handle);
printf("\n");
coolprintf("Binary to ASM Array Converter By EMiNENT DOOM");
printf("\n\n");
coolprintf("Input Array Name:");
coolgets(array_name);
printf("\r ");
fprintf(fp,"%s label byte \r\ndb ",array_name);
for(count=0;count<=fl;count++)
{
read(handle, buf, 1);
if(count==fl) fprintf(fp,"%d",buf[0]);
else if(count2<=17) fprintf(fp,"%3d,",buf[0]);
else if(count2==18) fprintf(fp,"%3d",buf[0]);
if(count2++ >=18)
{
count2=0;
fprintf(fp,"\ndb ");
printf("\r");
sprintf(string,"Line: %d",line);
coolprintf(string);
line++;
}
}
printf("\n");
fclose(fp);
close(handle); /* close the file */
return 0;
}